package com.aiwu.memory;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.aiwu.BaseLazyFragment;
import com.aiwu.library.App;
import com.aiwu.library.util.DisplayUtil;

import org.citra.citra_emu.R;

/**
 * 准确搜索
 * 回游戏改数值后的界面
 */
public class MemoryNormalBackGameFragment extends BaseLazyFragment implements OnActionCallback {
    private static final String TAG = MemoryNormalBackGameFragment.class.getName();
    private ViewGroup layoutContainer;
    private TextView tvTip;
    private EditText etNum;

    @Override
    protected void lazyLoad() {
        String tipStr = MemoryManager.getInstance().getLastSearchValue() + " 变成了";
        SpannableString ssTip = new SpannableString(tipStr);
        int start2 = 0;
        int end2 = (MemoryManager.getInstance().getLastSearchValue() + "").length();
        ssTip.setSpan(new ForegroundColorSpan(ContextCompat.getColor(App.getContext(), R.color.text_imp)), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvTip.setText(ssTip);
    }

    @Override
    protected Boolean repeatedLoad() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.fragment_memory_back_game_normal;
    }

    @Override
    protected void initView(View view) {
        layoutContainer = view.findViewById(R.id.layout_container);
        tvTip = view.findViewById(R.id.tv_tip);
        etNum = view.findViewById(R.id.et_num);
        MemoryManager.disableShowInput(etNum, true);
        MemoryManager.getInstance().addOnActionCallback(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MemoryManager.getInstance().removeOnActionCallback(this);
    }

    @Override
    public void onShowKeyboard() {
        if (getContext() != null) {
            if (DisplayUtil.isPortrait()) {
                layoutContainer.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.dialog_memory_content));
            } else {
                layoutContainer.setBackgroundResource(R.drawable.dialog_content_left);
            }
        }
    }

    @Override
    public void onCloseKeyboard() {
        if (getContext() != null) {
            layoutContainer.setBackgroundResource(R.drawable.dialog_content);
        }
    }
}
